package cn.fintecher.gis.service;

import cn.fintecher.gis.entity.BusinessLayer;
import cn.fintecher.gis.entity.DistrictInfo;
import cn.fintecher.gis.entity.QDistrictInfo;
import cn.fintecher.gis.enums.FlowType;
import cn.fintecher.gis.model.request.LayerInfoCreateRequest;
import cn.fintecher.gis.model.session.SessionModel;
import cn.fintecher.gis.respository.*;
import com.google.common.collect.Sets;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @Auther: xiaqun
 * @Description:
 * @Date: 17:57 2019/4/29
 */
public class BaseService {
    @Autowired
    protected ModelMapper modelMapper;

    @Autowired
    protected ReportInfoRepository reportInfoRepository;

    @Autowired
    protected ReportFileRepository reportFileRepository;

    @Autowired
    protected GrantInfoRepository grantInfoRepository;

    @Autowired
    protected GrantFileRepository grantFileRepository;

    @Autowired
    protected ExpropriationRepository expropriationRepository;

    @Autowired
    protected ExpropriationFileRepository expropriationFileRepository;

    @Autowired
    protected SupplyInfoRepository supplyInfoRepository;

    @Autowired
    protected SupplyFileRepository supplyFileRepository;

    @Autowired
    protected RestsInfoRepository restsInfoRepository;

    @Autowired
    protected RestsFileRepository restsFileRepository;

    @Autowired
    protected LayerInfoRepository layerInfoRepository;

    @Autowired
    protected LayerInfoService layerInfoService;

    @Autowired
    protected FlowService flowService;

    @Autowired
    private BusinessLayerService businessLayerService;

    @Autowired
    private DistrictInfoRepository districtInfoRepository;

    /**
     * 获取图层信息
     */
    BusinessLayer getLayerInfo(LayerInfoCreateRequest request, FlowType type, SessionModel model) throws Exception {
        return businessLayerService.createBusinessLayer(null, request.getFileId(),
                request.getLayerName(), request.getStyleNames(), type, model);
    }

    /**
     * 根据行政区id查询对应的行政区信息
     *
     * @param regions
     * @return
     */
    public Set<DistrictInfo> getDistrictInfoByIds(List<String> regions) {
        if (regions != null && !regions.isEmpty()) {
            Iterator<DistrictInfo> iterator = districtInfoRepository.findAll(QDistrictInfo.districtInfo.id.in(regions)).iterator();
            return Sets.newHashSet(iterator);
        } else {
            return null;
        }
    }

    public boolean listNotNull(List list) {
        if (list != null && !list.isEmpty()) {
            return true;
        }
        return false;
    }
}
